<?php
class ControllerBenBaocao extends Controller
{
	private $error = array();
   	function __construct() 
	{
	 	$this->load->model("ben/thuchi");
		$this->load->model("core/category");
		$this->data['chiphi'] = array();
		$this->model_core_category->getTree("chiphi",$this->data['chiphi']);
		unset($this->data['chiphi'][0]);
   	}
	
	public function index()
	{
		$this->getList();
	}
	
	public function thuchi()
	{
		
		
		$this->id='content';
		$this->template="ben/baocao_thuchi.tpl";
		$this->layout=$this->user->getLayout();
		$this->render();	
	}
	
	public function thuchishow()
	{
		$data = $this->request->post;
		$data['tungay'] = $this->date->formatViewDate($data['tungay']);
		$data['denngay'] = $this->date->formatViewDate($data['denngay']);
		if($this->validateForm($data))
		{
			$where = "AND ngaylap >= '".$data['tungay']."'";
			$where .= "AND ngaylap <= '".$data['denngay']." 24:00:00'";
			$this->data['data_phieuthu'] = $this->model_ben_thuchi->getList($where." AND loaithuchi = 'thu'");
			$this->data['data_phieuchi'] = $this->model_ben_thuchi->getList($where." AND loaithuchi = 'chi'");
			$this->id='content';
			$this->template="ben/baocao_thuchi_show.tpl";
			$this->render();	
		}
		else
		{
			foreach($this->error as $item)
			{
				$this->data['output'] .= $item."<br>";
			}
			$this->id='content';
			$this->template='common/output.tpl';
			$this->render();

		}
		
		
	}
	
	
	private function validateForm($data)
	{
		if (trim($data['tungay']) == "") 
		{
      		$this->error['tungay'] = "Bạn chưa chọn từ ngày";
    	}
		if (trim($data['denngay']) == "") 
		{
      		$this->error['denngay'] = "Bạn chưa chọn đến ngày";
    	}
		
		if($this->date->_compareDate($data['tungay'],$data['denngay']))
		{
			
		}
		
			
		if (count($this->error)==0) {
	  		return TRUE;
		} else {
	  		return FALSE;
		}
	}
	
}
?>